package com.leon.programPeral.ch1;

import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class Ch1Utils
{
	public static int[] getData(int cnt)
	{
		int[] res = new int[cnt];
		Set<Integer> set = new HashSet<>();
		int i = 0;
		int j = 0;
		while (i < cnt)
		{
			int i1 = new Random().nextInt(10000000);
			if (!set.contains(i1))
			{
				set.add(i1);
				res[j++] = i1;
				i++;
			}
		}
		return res;
	}

	@Test
	public void testgetData()
	{
		int[] data = getData(1000000);
		System.out.println(data.length);
//		System.out.println(JSONObject.toJSONString(data));
	}

	/**
	 * 由于 long 只能保存 20位，因此，a 最大只能为 20
	 * @param data
	 * @param a
	 */
	public void set(long data, int a)
	{

	}
}
